package com.blockmeta.bbs.immodule.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;

import com.blankj.utilcode.util.LogUtils;
import com.blockmeta.bbs.immodule.ClientService;
import com.blockmeta.bbs.immodule.broadcast.IMMsgDispatcher;
import com.blockmeta.bbs.immodule.dao.ChatMessage;
import com.blockmeta.bbs.immodule.dao.Todo;

public class IMClientService extends Service {


    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        LogUtils.i("authorkkk" + "clientservice onDestroy");
    }

    @Override
    public IBinder onBind(Intent intent) {
        return new LocalBinder();
    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return Service.START_REDELIVER_INTENT;

    }

    public class LocalBinder extends ClientService.Stub {

        public IMClientService getService() {
            return IMClientService.this;
        }


        @Override
        public void onReceiveData(Intent intent) throws RemoteException {
            String key = intent.getAction();
            LogUtils.d("pidtest " + android.os.Process.myPid());

            LogUtils.i("author" + "IMDataReceiver" + key + " " + intent.getData());
            if (!TextUtils.isEmpty(key)) {
                IMMsgDispatcher.getInstance().dispatch(key, intent);
            } else {
            }
        }

    }

    @Override
    public boolean onUnbind(Intent intent) {
        LogUtils.i("authorkkk" + "imclientservice unbindService");
        return super.onUnbind(intent);
    }

}
